package com.gaoxin.api.contronller.statisController;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.statisentity.User;
import com.gaoxin.api.service.statisservice.StatisClassNumberService;
import com.google.common.collect.Maps;

import io.swagger.annotations.Api;

/**
 * 统计班级数目controller
 * @author zhaozhenshe
 *2018-07-13
 */
@RestController
@RequestMapping("/app/statistics")
@Api(tags="统计班级数接口")
public class StaClassNumberController {
	@Autowired
	private StatisClassNumberService statisClassNumberService;
	/**
	 * @param userCode
	 * @return
	 */
	@RequestMapping(value = "/queryClassNum", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryClassNumber(@RequestBody Map<String,String> paramMap){
		String userCode = paramMap.get("userCode");
		String jsonData = null;
		try {
			User user = statisClassNumberService.queryUser(userCode);
			if(user==null){
				Map<String, Object> map = Maps.newLinkedHashMap();
				map.put("code","100501");
				map.put("errmsg","无该教师信息，请核对正确后重新输入！");
				jsonData = JSON.toJSONString(map);
				return jsonData;
			}
			User results = statisClassNumberService.queryClassNumber(userCode);
			Map<String, Object> map = Maps.newLinkedHashMap();
			if(results!=null){
				map.put("code","0");
				map.put("results",results);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code","100502");
				map.put("errmsg","无该教师所带班级信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}
}
